<?php
/**
 * JoiGallery Плагины
 *
 * Плагин "Все фото в категории - слайдер"
 * Плагин позволяет выводить изображения из той же категории, 
 * что и текущее, в виде прокручивающейся области
 *
 * @version 1.0
 * @package JoiGallery
 * @filename allcategoryphotosliders.php
 * @author JoostinaTeam
 * @copyright (C) 2008-2009 Joostina Team
 * @license see license.txt
 *
 **/
 
 class allCategoryPhotosSlider {

    var $_object    = null;
    var $_params    = null;
    var $_mainframe = null;
    var $_config    = null;
    
 
    function allCategoryPhotosSlider($plugin, $plugin_config){
        $this->_object    = $plugin->object;
        $this->_params    = $plugin->object_params;
        $this->_mainframe = $plugin->_mainframe;  
        $this->_config    = $plugin_config;
    }
    
    function show_content(){
        
        $this->_mainframe->addLib('text');
        
        $this->_mainframe->addCSS(JPATH_SITE.'/components/com_joigallery/plugins/foto-view/allCategoryPhotosSlider/css/style.css');
        $this->_mainframe->addJS(JPATH_SITE.'/components/com_joigallery/plugins/foto-view/allCategoryPhotosSlider/js/slider.js','js');

        $photos = $this->get_category_photos();
        if($photos && $this->_config->show_plugin) {
        ?>

        <script type="text/javascript">
        $(document).ready(function(){
              $( "#slider" ).accessNews({
              headline : "<?php  echo _C_JOIGALLERY_CONF_IMG_IN_CAT ?>",
              speed    : "normal",
              slideBy  : <?php  echo $this->_config->slide_by ?>
          });
        });
        </script>
            
        <div id="all_category_fotos">
          <?php if ($this->_config->title) 
            echo '<h3 class="gray">'.$this->_config->title.'</h3>';
          ?>

          <p class="next"><a class="el_next" id="next" href="#" title="вперед">вперед&nbsp;&rarr;</a></p>
          <p class="back"><a class="el_back" id="back" href="#" title="назад">&larr;&nbsp;назад</a></p>
          <div class="clrpx"></div>

          <div class="accessible_news_slider candy_coated" id="slider">
          

            <ul class="all_category_fotos">
               <?php foreach($photos as $photo){
                    $link = sefRelToAbs('index.php?option='.$this->_params->_option
                            .'&amp;act=photos&amp;cid='
                            .$photo->id.'&amp;Itemid='.$this->_params->_Itemid);

                    $photo->description = mosHTML::cleanText($photo->description);
                    $title = Text::character_limiter($photo->description, 100, '...');
                    ?>
                      <!--Фото-->
                      <li class="photo">

                        <a class="photo_thumb" href="<?php echo $link; ?>" title="<?php echo $photo->description;?>">
                          <img src="<?php echo JPATH_SITE.$this->_params->thumbnail_path.'/'.$photo->path; ?>"
                               border="0"
                               alt="<?php echo $photo->name; ?>"
                               title="<?php echo $title; ?>" />
                        </a>

                        <?php if($this->_config->show_name): ?>
                           <h4>
                             <a href="<?php echo $link; ?>"
                                title="<?php echo _SHOW.' '.$photo->name;?>">
                                <?php  echo $photo->name; ?>
                             </a>
                           </h4>
                        <?php endif;?>

                        <?php if($this->_config->show_desc) : ?>
                                <p><?php echo $photo->description; ?></p>
                        <?php endif;?>

                      </li>
                      <!--/Фото-->
               <?php } ?>
            </ul>

          </div>

        </div>
 
           
        <?php
        }


    }
    
    function get_category_photos($limit = ''){
        
        $database = &database::getInstance();
        
        if($limit){
            $limit = ' LIMIT '.$limit;
        }
        
    	$query = 'SELECT id, ordering,  description, path, name FROM #__joigallery 
      	WHERE cid = ' . (int)$this->_object->cid . ' AND state = 1  AND id != ' . (int)$this->_object->id .' 
      	ORDER BY ordering DESC '.$limit;

        $database->setQuery( $query );
        return $database->loadObjectList();   
                
    }
    
 }
 
 
 class allCategoryPhotosSliderConfig {
    
    var $_plugin = null;
    var $_description = null;    
    
    var $type = 'foto-view';
    var $show_plugin = 1;
    var $title = 'Еще фото в категории';    
    var $show_name = 0;
    var $show_desc = 0;
    var $slide_by = '1';
    
    
    function allCategoryPhotosSliderConfig($plugin){
        $this->_plugin = $plugin;    
    }
    
    function display_config(){        
        $mainframe = &mosMainFrame::getInstance();                
        require_once(JPATH_BASE.DS.'components'.DS.'com_joigallery'.DS.'plugins'.DS.'foto-view'.
        DS.'allCategoryPhotosSlider'.DS.'display_config.php');    
    }
    
 }
